import Vue from 'vue';

/**
 * 防止按钮重复点击事件
 *
 * v-preventReClick="2000"
 */
Vue.directive('preventReClick', {
    inserted(el: HTMLInputElement, binding) {
        let timer = null;
        el.addEventListener('click', () => {
            if (!el.disabled) {
                el.disabled = true;
                timer = setTimeout(() => {
                    el.disabled = false;
                }, Number(binding.value) || 2000);
            }
        });
    },
});
